package com.hdoit.apollo.web.billing.controllers;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.hdoit.apollo.logical.billing.mapper.BillingMapper;
import com.hdoit.apollo.logical.billing.model.Billing;
import com.hdoit.apollo.logical.billing.service.IBillingService;
import com.hdoit.apollo.logical.viewmodel.billing.BillingSearch;
import com.tennetcn.authority.component.web.BaseController;
import com.tennetcn.data.message.PagerModel;
import com.tennetcn.web.message.WebManageContainer;

/**
 * @author      tancongzhu
 * @email       
 * @createtime  2018年04月26日 11:04:02
 * @comment
 */
@Controller
@RequestMapping(value = "/billing/close/")
public class CloseController extends BaseController{
    @Override
    public String getRoutePath() {
        return "areas/billing/close/";
    }

    @Autowired
    private IBillingService billingService;
    
    @Autowired
    private BillingMapper billingMapper;
    
    private final String indexViewName="index";
    private final String outputViewName="output";
    private final String detailedViewName="detailed";
    private final String detailedPrint="detailedPrint";

    @RequestMapping(value = indexViewName, method = { RequestMethod.GET,RequestMethod.POST })
    public String index(Model model,PagerModel pagerModel,BillingSearch search,boolean ajaxPost,String level){
    	search.setType("close");
        pagerModel.setTotalAmount(billingMapper.queryCountMPForPc(search));
        List<Billing> billings= billingMapper.queryListMPForPc(search,pagerModel);

        model.addAttribute(WebManageContainer.PAGERKEY, pagerModel);
        model.addAttribute("billings", billings);
        model.addAttribute("billingSearch", search);
        model.addAttribute("level", level);
        
        if(ajaxPost){
            return view(outputViewName);
        }

        return view(indexViewName);
    }

    @RequestMapping(value = detailedViewName, method = { RequestMethod.GET})
    public String billingDetailed(Model model,String key){
        Billing billing=new Billing();
        if(!StringUtils.isEmpty(key)){
        	billing =billingService.getBillingByKey(key);
        	
        }

        model.addAttribute("billing", billing);
        return view(detailedViewName);
    }
    
    @RequestMapping(value = detailedPrint, method = { RequestMethod.GET})
    public String detailedPrint(Model model,String key){
        Billing billing=new Billing();
        if(!StringUtils.isEmpty(key)){
        	billing =billingService.getBillingByKey(key);
        	
        }
        model.addAttribute("billing", billing);
        return view(detailedPrint);
    }
}
